package com.xiahui.day11.Test6;

/**
 *  名字 年龄
 *  直接打印一个对象 相当于调用此对象的toString方法 toString方法从顶层父类Object类中继承而来
 *  我们在实际开发中通常需要重写toString方法 用于将本类中的属性名 和 属性值 进行拼接 以方便直接打印对象
 *  实现输出 属性信息的效果
 */
public class Student {
    String name;
    int age;
    char sex;
    double height;
    String hobby;

    @Override
    public String toString() {
        String s = super.toString();
        return s + "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", height=" + height +
                ", hobby='" + hobby + '\'' +
                '}';
    }
//    public String toString(){
//        return "Student[name = '"+ name +"',age = " + age +",sex = '"+sex +"',height = " + height + ",hobby = '"+hobby+"' ]";
//    }
//
//    public String printStudent(){
//        return "Student[name = '"+ name +"',age = " + age +",sex = '"+sex +"',height = " + height + ",hobby = '"+hobby+"' ]";
//    }

    public static void main(String[] args) {
        Student stu1 = new Student();
        stu1.name = "赵四";
        stu1.age = 20;
        stu1.height = 175;
        stu1.hobby = "尬舞";
        stu1.sex = '男';

        System.out.println(stu1);
        System.out.println(stu1.toString());

        System.out.println(stu1.name);
        System.out.println(stu1.age);
        System.out.println(stu1.height);
        System.out.println(stu1.hobby);
        System.out.println(stu1.sex);


    }
}

